/**存放公共js文件 */
//临时新闻数据
const news = [{
  id: '1',
  title: '标题一',
  
  poster: 'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png',
  add_date: '2022-05-07',
  detail: '11111111111'
},
{
  id: '2',
  title: '标题二',
  poster: 'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png',
  add_date: '2022-05-08',
  detail:'22222222222222222'
},
{
  id: '3',
  title: '标题三',
  poster: 'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png',
  add_date: '2022-05-09',
  detail:''
},
{
  id: '4',
  title: '标题四',
  
  poster: 'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png',
  add_date: '2022-05-07',
  detail: '11111111111'
},
{
  id: '5',
  title: '标题五',
  
  poster: 'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png',
  add_date: '2022-05-07',
  detail: '11111111111'
},
{
  id: '6',
  title: '标题六',
  
  poster: 'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png',
  add_date: '2022-05-07',
  detail: '11111111111'
},
]

//获取新闻列表
function getNewList() {
let list = [];
for(var i = 0; i < news.length; i++) {
  let obj = {};
  obj.id = news[i].id;
  obj.poster = news[i].poster;
  obj.content = news[i].detail;
  obj.add_date = news[i].add_date;
  obj.title = news[i].title;
  // console.log('obj',obj);
  list.push(obj);
}
return list;
}

//获取新闻内容
function getNewsDetail(newsID) {
let message = {
  code: '404',
  news: {}
};
for (var i = 0; i < news.length; i++) {
  if (newsID == news[i].id) {
    message.code = '200',
      message.news = news[i];
    break;
  }
}
return message;
}

module.exports = {
getNewList : getNewList,
getNewsDetail : getNewsDetail
}

